package com.gt.acc

import com.gt.SCUtil
import org.apache.spark.SparkContext
import org.apache.spark.rdd.RDD

object Spark_acc_01 {

  def main(args: Array[String]): Unit = {
    val sc: SparkContext = SCUtil.buildLocalSc()
    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4, 5), 3)

    val sumAcc = sc.longAccumulator("sum")
    rdd.foreach(num =>{
      sumAcc.add(num)
    })

    println(sumAcc.value)
    sc.stop()

  }

}
